using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using User.Application.Contracts.DTOs;
using User.Application.Contracts.Interfaces;


namespace User.Infrastructure.Queries
{
    public class UserAppService : IUserAppService
    {
        private UserDbContext _context;
        public UserAppService(UserDbContext context)
        {
            _context = context;
        }

        public async Task<UserProfileDto?> GetUserProfileAsync(string userId)
        {
            var user = await _context.UserProfiles
                .Where(u => u.Id.ToString() == userId)
                .Select(u => new UserProfileDto
                {
                    NickName = u.NickName,
                    CreatedAt = u.CreatedAt,
                    LastLoginTime = u.LastLoginTime,
                    AvatarUrl = u.AvatarUrl,
                    PhoneNumber = u.PhoneNumber==null?null:u.PhoneNumber.Value,
                    Address = u.Address
                })
                .FirstOrDefaultAsync();
           
            return user;
        }
    }
}